/*
 * @Date: 2024-01-19 17:39:10
 * @LastEditors: wy
 * @LastEditTime: 2024-01-21 10:48:48
 * @FilePath: \商城\src\store\index.js
 */
import Vue from 'vue'
import Vuex from 'vuex'
// import app from './modules/app'
// import user from './modules/user'
// import settings from './modules/settings'
import getters from './getters'
// import common from './modules/common'

Vue.use(Vuex)

// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // set './app.js' => 'app'
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(modulePath)
  modules[moduleName] = value.default
  console.log('modules==',modules)
  return modules
}, {})

const store = new Vuex.Store({
  modules,
  getters
})


export default store
